"""
面向对象，动态绑定属性和方法
"""


class Student:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def eat(self):
        print(f"我是{self.name},我在吃饭")


stu1 = Student("张三", 20)
stu2 = Student("李四", 30)
print(id(stu1))
print(id(stu2))
# 为stu1动态绑定性别属性
stu1.gender = "女"
print(stu1.name, stu1.age, stu1.gender)
# print(stu2.name, stu2.age, stu2.gender) 报错，stu2未绑定性别属性

print("---------------------")
stu1.eat()
stu2.eat()


def show():
    print("定义在类之外的,称为函数")


# 动态绑定方法
stu2.show = show
stu2.show()
# stu1.show() 报错，stu1未绑定show方法
